/*
 * Copyright (c) 2019 - 2020 IoT Company of Midea Group.
 *
 * File Name 	    : 
 * Description	    : rtos adaptor
 *
 * Version	        : v0.1
 * Author			: 
 * Date	            : 2019/09/15  refactoring
 * History	        : 
 */
#ifndef __MS_OSAL_MEM_H__
#define __MS_OSAL_MEM_H__

#include <stdint.h>
#include "ms_osal.h"
#include "ms_osal_log.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum
{
    MS_OSAL_MEM_INFO_REQ_TYPE_PRINTF,   //
    MS_OSAL_MEM_INFO_REQ_TYPE_DATA,   //
} ms_osal_mem_info_req_type_t;

typedef struct
{
   /* the number of bytes of free heap.*/
   	uint32_t free_heap_size; 
   /* the max block of bytes of free heap*/
    uint32_t max_free_block_size;
}ms_osal_mem_info_t;

/**
 * @brief	allocate memory
 * @note    be similar to malloc
 * @param[in]	size : Size of the memory to be allocated
 * @return	Pointer to the allocated memory, NULL if allocation fails
 **/
void *ms_osal_memory_alloc(size_t size);

/**
 * @brief	allocate memory
 * @note    be similar to calloc
 * @param[in]	num : num of data 
 * @param[in]	size : size of data to be allocated
 * @return	Pointer to the allocated memory, NULL if allocation fails
 **/
void *ms_osal_memory_calloc(size_t num, size_t size);

/**
 * @brief	reallocate memory
 * @note    be similar to realloc
 * @param[in]	pointer : Pointer to the allocated memory
 * @param[in]	size : size of data to be reallocated
 * @return	Pointer to the allocated memory, NULL if allocation fails
 **/
void *ms_osal_memory_realloc(void *pointer, size_t size);

/**
* @brief	free memory
* @param[in]	pmem : Pointer to the memory to be freed
**/
void ms_osal_memory_free(void *pmem);

/**
 * @brief	query memory information
 * @param   type: whether get data of mem_info, or only printf single info
 * @param	pmem_info: Pointer to the memory informaiton
 * @return if successly, return MS_OSAL_RESULT_SUCCESS, \n
 *         otherwise return MS_OSAL_RESULT_ERROR
 */
ms_osal_result_t ms_osal_memory_info(ms_osal_mem_info_req_type_t type, ms_osal_mem_info_t *pmem_info);

/**
 * @brief   printf memory verbose info
 **/
void ms_osal_memory_dump_verbose_info(void);

#ifdef __cplusplus
}
#endif

#endif // __MS_OSAL_MEM_H__

